<template>
  <div class="fawen">
    <el-dialog
      title="批示意见/办理提示"
      :visible.sync="dialogVisible"
      width="60%">
      <notice :noticePersonId="noticePersonId" :step="selStep"></notice>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <el-breadcrumb separator=">">
      <el-breadcrumb-item :to="{ path: '/' }">系统首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/selection' }">干部选任</el-breadcrumb-item>
      <el-breadcrumb-item>任职发文</el-breadcrumb-item>
    </el-breadcrumb>
    <section class="wboxnoborder">
      <div :style="'height:'+tableHeight+'px'">
        <el-scrollbar style="height: calc(100% + 16px);">
          <div style="width:calc(100%-40px);padding:15px">
            <el-radio-group v-model="departmentCode" @change="changedept" style="margin-bottom:10px" class="pointRadio">
              <el-radio-button v-if="mangeDep.indexOf('干部一处')>-1" :label="1">
                <el-badge v-if="num1>0" :value="num1" class="item">干部一处事项</el-badge>
                <span v-else>干部一处事项</span>
              </el-radio-button>
              <el-radio-button v-if="mangeDep.indexOf('干部二处')>-1" :label="2">
                <el-badge v-if="num2>0" :value="num2" class="item">干部二处事项</el-badge>
                <span v-else>干部二处事项</span>
              </el-radio-button>
              <el-radio-button v-if="mangeDep.indexOf('干部三处')>-1" :label="3">
                <el-badge v-if="num3>0" :value="num3" class="item">干部三处事项</el-badge>
                <span v-else>干部三处事项</span>
              </el-radio-button>
            </el-radio-group>
          <el-table
            v-loading="listloading"
            border
            size="small"
            :data="tableData4"
            tooltip-effect="dark"
            style="width: 100%;"
            @selection-change="handleSelectionChange4">
            <el-table-column
              type="selection"
              width="55">
            </el-table-column>
            <el-table-column
              label="序号"
              type="index"
              width="50">
            </el-table-column>
            <el-table-column
              prop="realName"
              label="姓名"
              width="150">
            </el-table-column>
            <el-table-column
              prop="unitName"
              width="150"
              label="选任岗位单位"
              show-overflow-tooltip>
            </el-table-column>
            <el-table-column
              prop="jobName"
              width="150"
              label="选任岗位职务"
              show-overflow-tooltip>
            </el-table-column>
            <el-table-column
              prop="jobLevel"
              label="选任岗位职级"
              width="150"
              show-overflow-tooltip>
            </el-table-column>
            <el-table-column
              label="任职文号"
              width="280" prop="docno">
            </el-table-column>
            <el-table-column
              label="任职时间"
              width="180" >
              <template slot-scope="scope">
                {{scope.row.arrivalTime}}
              </template>
            </el-table-column>
            <el-table-column label="是否有试用期" width="120">
              <template slot-scope="scope">
                {{scope.row.probationPeriod===1?'是':'否'}}
              </template>
            </el-table-column>
            <el-table-column
              label="附件">
              <template slot-scope="scope">
                <el-link v-for="item of scope.row.files"
                  :key="item.id"
                  type="primary"
                  :href="$http.defaults.baseURL+$http.defaults.selectionAPI+'api/gen/file/download?id='+item.id"
                  class="marginL8"
                  target="_blank">{{item.fileName}}.{{item.fileType}}</el-link>
              </template>
            </el-table-column>
            <el-table-column
              label="办理提示、批示意见"
              width="180">
              <template slot-scope="scope">
                    <el-popover placement="bottom" width="600" trigger="hover">
                      <notice :noticePersonId="scope.row.personId" step="8"></notice>
                      <el-button size="small" slot="reference" type="primary" @click="showNotice(scope.row.personId)">查看详情</el-button>
                    </el-popover>
              </template>
            </el-table-column>
          </el-table>
          </div>
          <select-group :backflag="false" :selectData="selectData" :selectPerson="selectPerson2" :selApi="selApi" :selStep="selStep" @getList="getList4"></select-group>
        </el-scrollbar>
      </div>
    </section>
  </div>
</template>

<script>
import selectGroup from '../common/SelectGroup2'
import notice from '../common/Notice'
export default {
  name: 'fawen',
  components: {
    selectGroup,
    notice
  },
  data () {
    return {
      num1: 0,
      num2: 0,
      num3: 0,
      listloading: false,
      mangeDep: '',
      departmentCode: '',
      tabdept: '1',
      tableHeight: 100,
      tableData4: [],
      selectData: {
        hjData: [
        ],
        szData: [
        ],
        cnData: [
        ],
        yyData: []
      },
      selectPerson: [], // 待批示
      selectPerson2: [], // 已批示
      selApi: 'api/selection/postdispatch/submitApprove',
      selStep: 8,
      noticePersonId: '', // notice persion id
      dialogVisible: false // 已批示
    }
  },
  methods: {
    showNotice (id) { // 已批示 批示意见
      console.log('show notice id:', id)
      this.noticePersonId = id
      this.dialogVisible = true
    },
    getNum () {
      let url = this.$http.defaults.selectionAPI + 'api/selection/statnum/postdispatch/getStatNum2'
      // console.log(url)
      this.$http.get(url).then(res => {
        if (res.data.success === true) {
          this.num1 = res.data.result.num1
          this.num2 = res.data.result.num2
          this.num3 = res.data.result.num3
        } else {
          this.$message({
            message: '数据获取失败',
            type: 'error'
          })
        }
      })
    },
    changedept () {
      this.selectData.hjData = []
      this.selectData.szData = []
      this.selectData.yyData = []
      this.loadSelectData()
      this.getList4()
    },
    loadSelectData () {
      let departmentName = ''
      if (this.departmentCode === 1) {
        departmentName = '干部一处'
      } else if (this.departmentCode === 2) {
        departmentName = '干部二处'
      } else if (this.departmentCode === 3) {
        departmentName = '干部三处'
      }
      this.$http
        .get(this.$http.defaults.selectionAPI + `api/selection/auth/getUsersByRole?roletype=1`)
        .then(response => {
          if (response.data.success) {
            this.selectData.hjData = []
            for (let i = 0; i < response.data.result.length; i++) {
              if (response.data.result[i].unitName === departmentName) {
                this.selectData.hjData.push(response.data.result[i])
              }
            }
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
      this.$http
        .get(this.$http.defaults.selectionAPI + `api/selection/auth/getUsersByRole?roletype=2`)
        .then(response => {
          if (response.data.success) {
            this.selectData.szData = []
            for (let i = 0; i < response.data.result.length; i++) {
              if (response.data.result[i].roleName === 'ROLE_sizhang' || response.data.result[i].manageDep.indexOf(departmentName) > -1) {
                this.selectData.szData.push(response.data.result[i])
              }
            }
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
      this.$http
        .get(this.$http.defaults.selectionAPI + `api/selection/home/getCommonlyOpinions?step=8`)
        .then(response => {
          if (response.data.success) {
            this.selectData.yyData = response.data.result
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
    },
    getList4 () {
      this.getNum()
      this.listloading = true
      let url = this.$http.defaults.selectionAPI + 'api/selection/postdispatch/getApprove'
      // console.log(url)
      this.$http.get(url + '?departmentCode=' + this.departmentCode).then(res => {
        this.listloading = false
        console.log('get list44 succ:', res)
        if (res.data.success === true) {
          this.tableData4 = res.data.result
        } else {
          this.$message({
            message: '数据获取失败',
            type: 'error'
          })
        }
      })
    },
    handleSelectionChange4 (val) { // 已批示
      console.log('tabledata4 val:', val)
      this.selectPerson2 = [...val]
    },
    tableresize (obj) {
      var clientHeight = 0
      if (document.body.clientHeight && document.documentElement.clientHeight) {
        clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      } else {
        clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      }
      obj.$nextTick(function () {
        obj.tableHeight = clientHeight - 165
      })
    }
  },
  mounted () {
    this.mangeDep = localStorage.getItem('mangeDep')
    if (!this.mangeDep || this.mangeDep === '') {
      this.mangeDep = []
    }
    let departmentCodes = []
    if (this.mangeDep.indexOf('干部一处') > -1) {
      departmentCodes.push(1)
    }
    if (this.mangeDep.indexOf('干部二处') > -1) {
      departmentCodes.push(2)
    }
    if (this.mangeDep.indexOf('干部三处') > -1) {
      departmentCodes.push(3)
    }
    this.departmentCode = departmentCodes[0]
    this.loadSelectData()
    // let params = this.$route.params
    // console.log('讨论决定详情params:', params)
    // 代办理列表
    this.getList4()
    // resize
    this.tableresize(this)
    let _this = this
    window.onresize = function windowResize () {
      // 通过捕获系统的onresize事件触发我们需要执行的事件
      _this.tableresize(_this)
    }
  }
}
</script>

<style>
.fawen .el-table--border td, .el-table--border th, .el-table__body-wrapper .el-table--border.is-scrolling-left~.el-table__fixed{
  border-bottom:1px solid #95B8E7;
}
.fawen .el-table td, .el-table th.is-leaf{
  border-right:1px solid #95B8E7;
}
.fawen .wboxnoborder .el-table{
  border: #95B8E7 solid 1px;
}
.fawen .wboxnoborder .el-table th{
  font-weight: normal;
  background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
  text-align: center;
  border-right: #95B8E7 solid 1px;
  border-bottom: #95B8E7 solid 1px;
  min-height: 30px;
  line-height:30px;
}
.fawen .wboxnoborder .el-table td, .el-table th{
  padding:0;
  font-size:var(--size14) !important;
  line-height: 20px;
  font-family: '宋体';
  text-align: center;
}
.fawen .el-table__row{
  height: 50px;
}
</style>
<style scoped>
.fawen {
  width: 100%;
}
.fawen-tit {
  width: 100%;
  height: 50px;
  line-height: 50px;
  padding: 0 8px;
  box-sizing: border-box;
  font-size: 15px;
  font-weight: bolder;
}
.fawen .wboxnoborder {
  padding: 0;
  width: 100%;
  background-color: #fff;
  margin: 0 10px;
  overflow: hidden;
}
</style>
